package atguigu.demo1

import scala.math._

/**
  * Created by lzd on 2018/10/23.
  */
object demo1 {
  def main(args: Array[String]): Unit = {
    /** val var */
    val a = 2 * 2
    println(a)
    var b = 2 * 2
    b = 5
    println(b)
    val c, d: String = "hello"
    println(c, d)

    /** 隐式转化 */
    println(1.toString)
    println("123".toInt)

    println(1.to(10))
    //找交集
    println("hello".intersect("lloaa"))

    /** 没有++、--操作符 */
    var a3 = 0
    a3 += 1
    println(a3)
    a3 -= 1
    println(a3)

    /** 提供BigInt和BigDecimal对象来处理大数据 */
    val x: BigInt = 1234567890
    println(x * x * x)
    val y: BigDecimal = 123.567
    println(y)

    /** 函数调用 */
    println(sqrt(9)) //求根
    println(pow(2, 4)) //2的4次方
    println(min(3, Pi))

    println("Hello".distinct)

    println(BigInt.probablePrime(100, scala.util.Random))

    /** apply */
    println("Hello" (4))
    println("Hello".apply(4))

    val arr = Array(1, 2, 3)
    val arr2 = Array.apply(1, 2, 3)
    println(arr.toBuffer)
    println(arr2.toBuffer)

    println(BigInt("1234567890"))
    println(BigInt.apply("1234567890"))


    arr(1) = 11
    arr.update(2, 22)
    println(arr.toBuffer)


    /**option 包装器 ，只有两个对象，一个some代表有值，一个none代表没值*/
    val scores = Map("Alice" -> "hihi" ,"Fred"->2)
    scores.get("Alice") match {
      case Some(s_val) => println(s_val)
      case None => println("No s_val")
    }

    scores.get("Hello") match {
      case Some(s_val) => println(s_val)
      case None => println("No s_val")
    }

    val res = scores.get("Hello")
    if(res.isEmpty) println("yes") else println("no")

    println(res.getOrElse("No score"))

    for (score <- scores.get("Alice")) println(score)

    scores.get("Alice").foreach(println _)
  }
}
